#include "magicbrushatd.h"

MagicBrushATD::MagicBrushATD()
{
    magic = MagicBrushTool::getInstance();
}

void MagicBrushATD::testRGB(){
    TestDriver::resTest(1, false, magic->setColourTolerance(MagicBrushTool::RED, 101));
    TestDriver::resTest(2, false, magic->setColourTolerance(MagicBrushTool::GREEN, -1));
    TestDriver::resTest(3, true, magic->setColourTolerance(MagicBrushTool::BLUE, 100));
    TestDriver::resTest(4, true, magic->setColourTolerance(MagicBrushTool::BLUE, 0));
    TEST(5, magic->blueTolerance==0);
}

void MagicBrushATD::testSelectedVoxel(){
    vector3<int> current = REND->mouseUtils.getMouseOverVoxelPt(30,30);
    voxel v;
    QMouseEvent * a = new QMouseEvent(QEvent::MouseButtonPress,
                                      QPoint(30, 30), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
    TestDriver::resTest(6, false, magic->mousePressEvent(a));
    REND->addVoxel(current.x, current.y, current.z, v);
    TestDriver::resTest(7, true, magic->mousePressEvent(a));
    magic->global->clearSelection();
}

void MagicBrushATD::testContinguous(){
    BrushUtilities* brush = BrushUtilities::getInstance();
    magic->isContiguous = true;
    brush->global->setRGB(0,100,0);
    brush->coords = vector3<int>(20,20,20);
    brush->setSize(5);
    brush->setShape(BrushUtilities::CUBE);
    brush->execute(BrushUtilities::ADD);
    brush->setSize(2);
    brush->execute(BrushUtilities::ERASE);
    brush->global->setRGB(200,0,0);
    brush->execute(BrushUtilities::ADD);

    magic->coords = brush->coords;
    magic->action = MagicBrushTool::ADD;
    TestDriver::resTest(8, true, magic->execute());
    TEST(9, magic->global->findInSelection(19,21,21)==true);
    TEST(10, magic->global->findInSelection(22, 22, 22)==false);
    TEST(11, REND->isVoxelDrawn(22,22, 22)==true);

    brush->setSize(5);
    brush->execute(BrushUtilities::ERASE);
    magic->global->clearSelection();

}

void MagicBrushATD::testNonContiguous(){
    voxel v;
   v.setColor(0,100,0);
    magic->isContiguous = false;
    REND->addVoxel(50,50,50, v);
    REND->addVoxel(100, 100, 100, v);
    magic->coords = vector3<int>(50,50,50);
    TestDriver::resTest(12, true, magic->execute());
    TEST(13, magic->global->findInSelection(100, 100, 100) && magic->global->findInSelection(50,50,50)==true);
    magic->global->clearSelection();
    REND->removeVoxel(50, 50, 50);
    REND->removeVoxel(100, 100, 100);
}

void MagicBrushATD::testVoxelInSelection(){
    SelectionTool* select = SelectionTool::getInstance();
    BrushUtilities* brush = BrushUtilities::getInstance();
    brush->coords = vector3<int>(150, 50, 100);
    brush->setSize(20);
    select->startCoords = vector3<int>(150, 50, 100);
    select->endCoords = vector3<int>(160, 60, 110);
    select->action = SelectionTool::ADD;
    select->execute();
    TEST(14, magic->global->findInSelection(160, 59, 109)==false);
    magic->coords = vector3<int>(150, 50, 100);
    magic->action=MagicBrushTool::ADD;
    magic->execute();
    TEST(15, magic->global->findInSelection(160, 59, 109)==false);
    brush->execute(BrushUtilities::ERASE);
    magic->global->clearSelection();

}
